<?php
    include_once ("../data/MySql.php");
    include_once ("../entity/Usuarios.php");
    class reporte{
        public $usuario_crea;
        public $usuario_modi;
        public $usuario;
        public $resulto;
        public $estado;
        public $tickets;
        public $porcentaje;
    }
    
    $desde = "2014-11-15";
                    $hasta = "2014-11-16";
                    $sql = "CALL SGISS_REPORTE_TICKET_X_FECHA('$desde','$hasta')";
                    $cx = new dal();
                    $result = $cx->execute($sql);
                    
                    while ($fila = mysqli_fetch_object($result)){
                        $obj = new Usuarios();
                        $obj->CODIGO = $fila->CODIGO;
                        $obj->ID_TICKET = $fila->ID_TICKET;
                        $obj->ID_MULTA = $fila->ID_MULTA;
                        $obj->ACTIVIDAD = $fila->ACTIVIDAD;
                        $obj->AUDFECCREACION = $fila->AUDFECCREACION;
                        $obj->AUDUSUCREACION = $fila->AUDUSUCREACION;
                        $obj->AUDFECMODIFICACION = $fila->AUDFECMODIFICACION;
                        $obj->AUDUSUMODIFICACION = $fila->AUDUSUMODIFICACION;
                        $obj->USUCREACION = $fila->USUCREACION;
                        $obj->USUMODIFICACION = $fila->USUMODIFICACION;
                        $ticket[]=$obj;
                    }
                    
                    $sql1 = "SELECT DISTINCT U.LOGIN USUCREACION FROM T_SCOB_HISTORIAL AS TH INNER JOIN T_SCOB_USUARIO AS U ON(U.ID_USUARIO = TH.AUDUSUCREACION) WHERE (TH.AUDFECCREACION >= '2014-11-15') AND (TH.AUDFECMODIFICACION <= '2014-11-16')";
                    $result1 = $cx->execute($sql1);
                    
                    while ($fila = mysqli_fetch_object($result1)){
                        $rep = new reporte();
                        $rep->usuario = $fila->USUCREACION;
                        $usuarios[] = $rep;
                    }
                    $total_ticket = 0;
                    
                    foreach ($usuarios as $usu){
                        $c = 0;
                        $o =0;
                        foreach ($ticket as $tic){
                            if($usu->usuario == $tic->USUCREACION && $usu->usuario == $tic->USUMODIFICACION){
                                $c++;
                            }elseif($usu->usuario == $tic->USUCREACION && $usu->usuario != $tic->USUMODIFICACION){
                                $o++;
                            }
                            $total_ticket++;
                        }
                        $usu->tickets = $c;
                        $usu->porcentaje = ($c / $total_ticket)*100;
                    }
                    $total = $total_ticket;
                    $rep1 = new reporte();
                    $rep1->usuario = "Otros";
                    $rep1->tickets = $o;
                    $rep1->porcentaje = ($o / $total)*100;
                    $usuarios[]=$rep1;
                    
//                    $datos = array();
                    $usu = array();
                    foreach ($usuarios as $usu2){
//                        $usu[0] = $usu2->usuario;
//                        $usu[1] = number_format($usu2->porcentaje,2);
                       $datos[] = "['".$usu2->usuario."',".number_format($usu2->porcentaje,2)."]";
//                        array_push($datos,$usu);
                    }
//                    print json_encode($datos);
?>
